<template>
  <div class="swiper-container">
    <swiper class="swiper" :modules="[Navigation,Pagination]" :pagination="pagination" @navigationChange="navigationChange">
      <SwiperSlide class="swiper-slide" v-for="item in 3">swiper-slide-{{ item }}</SwiperSlide>
    </swiper>
    <!-- 自定义分页容器，比如放在什么位置，或者什么样式 -->
    <div class="swiper-pagination"></div>
  </div>
</template>
<script setup lang="ts">
import { Swiper, SwiperSlide } from 'swiper/vue';
import { Navigation, Pagination } from 'swiper/modules';
import type { PaginationOptions } from 'swiper/types';
import 'swiper/css/navigation';
import 'swiper/css/pagination';
import 'swiper/css'


const pagination:PaginationOptions  = {
  el: '.swiper-pagination',
  clickable: true,
  dynamicBullets: true,
  type: 'bullets',
  // 自定义分页item样式
  renderBullet: (index:any, className:any) => `<span class="${className}">${index + 1}</span>`,
}

const navigationChange = (swiper:any) => {
  console.log(swiper);
}
</script>
<style scoped lang="scss">
.swiper-container{
  width: 100%;
  height: 100%;
  position: relative;
  .swiper{
    width: 100%;
    height: 100%;
  }
  .swiper-slide{
    width: 100% !important;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: antiquewhite;
    background-color: #ccc;
  }
  .swiper-pagination{
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: antiquewhite;
    background-color: #ccc;
  }
}
:deep(.swiper-pagination-bullet) {
  width: 20px;
  height: 20px;
  text-align: center;
  line-height: 20px;
  font-size: 12px;
  color: #000;
  opacity: 1;
  background: rgba(0, 0, 0, 0.2);
}

:deep(.swiper-pagination-bullet-active) {
  color: #fff;
  background: #007aff;
}
</style>
